package org.ruanjj.rotate;

class Solution {
    public void rotate(int[] nums, int k) {
        int n = nums.length;
        if(k >= n){
            k = k%n;
        }
        if(k == 0){
            return;
        }

        int[] tmp = new int[k];
        int m = k-1;
        for(int j = n-1; j >= 0; j--){
            if(j >= n-k){
                tmp[m] = nums[j];
                m--;
            }else{
                nums[j+k] = nums[j];
            }

            if(j < k){
                nums[j] = tmp[j];
            }
        }
    }
}
